<!-- 任务执行情况 -->
<template>
  <div>
    <el-dialog title="任务执行情况" :visible.sync="dialogTableVisible" @close="$emit('update:visible',false)"
               :close-on-click-modal="false"
               width="660px">
      <el-table :data="taskList"
                :stripe="tableStripe"
                :border="tableBorder"
                tooltip-effect="dark"
                ref="table">
        <el-table-column label="处理时间" prop="update_time" width="180"></el-table-column>
        <el-table-column label="任务人" prop="user_id" width="80" class="c-success">
          <template slot-scope="scope">
            <div class="userNameList">
              <p>{{scope.row.user_id}}</p>
              <p @click="checkhistoryLine" class="privetList" v-if="scope.row.is_end=='已转派'">转派人</p>
              <p @click="checkhistoryLine" class="privetList privetListSuccess" v-else>执行人</p>
            </div>
          </template>
        </el-table-column>
        <el-table-column label="任务处理">
          <template slot-scope="scope">
            <div v-if="scope.row.reply">
              <div v-if="scope.row.is_end=='未处理'">
                <span class="c-danger">暂无处理信息</span>
              </div>
              <div v-else>
                <div class="replyBodyBox">
                  <div>{{scope.row.reply}}</div>
                  <div v-if="scope.row.reply_pic" class="checkImg" @click="privaStatusFn(1,scope.row.reply_pic)">查看执行图
                  </div>
                  <div class="timereply">处理时间：{{scope.row.update_time}}</div>
                </div>
                <!--adminUserId 发布人 user_id 当前用户 doer_id 列表用户id-->
                <div v-if="scope.row.is_end=='完成'">
                  <div>
                    <!--// 只有发布人才可以进行回复评论-->
                    <el-button v-if="!scope.row.evaluate&&adminUserId==user_id" type="success" size="small"
                               @click="taskDetail(scope.row)">评论
                    </el-button>
                    <div v-if="scope.row.evaluate" class="evaluateBox">
                      <span>评论：</span>
                      <div class="evaluateBox_right">
                        <div>{{scope.row.evaluate}}</div>
                        <p class="checkImg" @click="privaStatusFn(2, scope.row.evaluate_pic)"
                           v-if="scope.row.evaluate_pic">
                          查看评论图</p>
                      </div>
                    </div>
                  </div>
                </div>
              </div>
            </div>
            <div v-else>
              <div v-if="scope.row.is_end!=='执行中'">
                <span class="c-danger">未接受任务</span>
              </div>
              <div v-else>
                <span class="c-success">执行中</span>
              </div>
            </div>
          </template>
        </el-table-column>
        <el-table-column label="状态" width="80">
          <template slot-scope="scope">
            <span class="c-success" v-if="scope.row.is_end=='完成'|| scope.row.is_end=='已转派'">{{scope.row.is_end}}</span>
            <span class="c-danger" v-else>{{scope.row.is_end}}</span>
          </template>
        </el-table-column>
      </el-table>
      <!--<el-pagination-->
              <!--:page-size="pageSize"-->
              <!--layout="prev, pager, next"-->
              <!--:total="taskPageTotal"-->
              <!--@current-change="handleSizeChange">-->
      <!--</el-pagination>-->
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="$emit('update:visible',false)" size="small">确 定</el-button>
      </div>
    </el-dialog>
    <!--detail 任务详情信息 getUser 执行函数 commonType回复类型，1去执行 2管理员评论-->
    <!--<teskCommon :visible.sync="commonvisible" v-if="commonvisible" @getUser="getUser" :detail="info"-->
                <!--:commonType="commonType"></teskCommon>-->
    <!---->
    <teskCommon :visible.sync="commonvisible" v-if="commonvisible" @getUser="getUser" :detail="editForm"
                :commonType="commonType" :taskUserId="taskUserId"></teskCommon>
    <!--    图片弹窗-->
    <previewImgDialog :privaImgObj="privaImgObj" :visible.sync="dialogImgVisible"
                      :privaStatus="privaStatus"></previewImgDialog>
  </div>
</template>
<script>
  import teskCommon from '@/components/dialog/taskCommonDialog.vue'
import previewImgDialog from '@/components/dialog/previewImgDialog.vue'

export default {
    name: 'taskListDialog',
    props: ['visible', 'taskId'],
    watch: {
      visible () {
        console.log(this.visible)
        this.dialogTableVisible = this.visible
      }
    },
    components: {
      teskCommon,
      previewImgDialog
    },
    data () {
      return {
        tableStripe: true, // 是否斑马栏
        tableBorder: true, // 单元格右边边框
        dialogImgVisible: false,
        privaStatus: null, // 1 执行回复 2 评论回复
        privaImgObj: null,
        commonvisible: false,
        dialogTableVisible: this.visible,
        taskList: [],
        adminUserId: null,
        user_id: null,
        taskPageTotal: 0,
        editForm: null,
        commonType: 2, // commonType 回复类型，1 去执行 2 管理员评论
        taskUserId: ''
      }
    },
    created () {
      this.db.findOne({
        name: 'user_id'
      }, (err, ret) => {
        this.user_id = ret.value
      })
      console.log('收到的id：', this.taskId, this.dialogTableVisible)
      this.InitFn()
    },
    methods: {
      InitFn () {
        this.$fetch('task/replylist/id/' + this.taskId, {p: this.detailPage}).then((response) => {
          console.log('数据：', response)
          if (response.result === 1) {
            this.taskList = response.list
            // this.taskPageTotal = response.list.total
            this.adminUserId = response.admin_id // 发布人
            // 处理数据
            let listOut = {}
            let listUserList = {} // 原始发起人
            for (let i in response.list) {
              listOut[response.list[i].user_id] = response.list[i]
              if (!response.list[i].from_id) {
                listUserList[response.list[i].user_id] = response.list[i]
              }
            }
            console.log('整理数据：', listOut)
            console.log('原始接收人：', listUserList)
            // end
          } else {
          }
        }).catch((err) => {
          console.log(err)
        })
      },
      taskDetail (option) {
        console.log('开启评论')
        option.taskName = option.user_id
        this.taskUserId = option.id
        this.editForm = option
        this.commonvisible = true
      },
      getUser () {
        this.InitFn()
      },
      privaStatusFn (option, privaImg) {
        let privaImgList = privaImg
        if (privaImg) {
          privaImgList = privaImg.split(',')
          for (let i in privaImgList) {
            privaImgList[i] = privaImgList[i]
          }
        }
        this.privaImgObj = privaImgList
        this.privaStatus = option
        this.dialogImgVisible = true
      },
      // 转派记录
      checkhistoryLine () {
        // this.$fetch('task/transfer/id/35/user_id/8', {}).then((response) => {
        //   if (response.result === 1) {
        //   } else {
        //   }
        // }).catch((err) => {
        //   console.log(err)
        // })
      }
    }
  }
</script>
